package com.fc.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.JdbcType;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;


@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "expense",autoResultMap = true) // 开启自动结果映射
public class Expense implements Serializable {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    private Long logisticsId;
    private Long driverId;
    @TableField(value = "date")
    private LocalDateTime date;//记录时间
    private String vehiclePlate;//车辆车牌号

    private BigDecimal fuel;//油费
    private BigDecimal urea;//尿素费用
    private BigDecimal washing;//洗车费用
    private BigDecimal repair;//维修费用
    private BigDecimal maintenance;//保养费用
    private BigDecimal tire;//补胎费用
    private BigDecimal temporary;//临时过路费
    //审核状态，0（待审核）、1（审核通过）、2（驳回）
    private Integer status;
    // 指定 JSON 字段处理器
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<String> imagePaths;//图片路径集合

    private Long reviewUser;
    @TableField(value = "review_time")
    private LocalDateTime reviewTime;


    /**
     * 计算所有费用的总和
     * @return 所有费用的总和
     */
    public BigDecimal getTotal() {
        return fuel == null ? BigDecimal.ZERO : fuel
                .add(urea == null ? BigDecimal.ZERO : urea)
                .add(washing == null ? BigDecimal.ZERO : washing)
                .add(repair == null ? BigDecimal.ZERO : repair)
                .add(maintenance == null ? BigDecimal.ZERO : maintenance)
                .add(tire == null ? BigDecimal.ZERO : tire)
                .add(temporary == null ? BigDecimal.ZERO : temporary);
    }

}
